﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using RollBackLib.src.utils;
using RollBackLib.src.core;

namespace RollBack.src.ui
{
    /// <summary>
    /// Displays the result of running a job in the form of a listview.
    /// </summary>
    public partial class RunStatsView : UserControl
    {
        public RunStatsView()
        {
            InitializeComponent();
        }

        public void addToJobRunStats(BackupStatistics stats)
        {
            this.SuspendLayout();
            listView1.Items.Clear();
            long totalFileScannedBytes = stats.m_fileStats.m_inProgress + stats.m_fileStats.m_totalBytesScanned;
            long totalFileCopiedBytes = stats.m_fileStats.m_totalBytesCopied;
            ListViewItem item1 = new ListViewItem(new string[] {
                    "Folder",
                    "" + (stats.m_dirStats.m_copied + stats.m_dirStats.m_created),
                    "" + (stats.m_dirStats.m_copied + stats.m_dirStats.m_created),
                    "" + stats.m_dirStats.m_inProgress + " of " + stats.m_dirStats.m_currentSize,
                    "" + stats.m_dirStats.m_skipped,
                    AppUtils.toHumanReadableSize(totalFileScannedBytes),
                    "" + stats.m_dirStats.m_deleted,
                    "" /* number of errors */
                });

            ListViewItem item2 = new ListViewItem(new string[] {
                    "File",
                    "" + (stats.m_fileStats.m_copied + stats.m_fileStats.m_skipped),
                    "" + stats.m_fileStats.m_copied,
                    AppUtils.toHumanReadableSize(stats.m_fileStats.m_inProgress)  + " of " + AppUtils.toHumanReadableSize(stats.m_fileStats.m_currentSize),
                    "" + stats.m_fileStats.m_skipped,
                    AppUtils.toHumanReadableSize(totalFileCopiedBytes),
                    "" + stats.m_fileStats.m_deleted,
                    "" + stats.m_fileStats.m_numErrors
                });
            listView1.Items.Add(item1);
            listView1.Items.Add(item2);
            this.ResumeLayout(false);
        }

        /// <summary>
        /// Reduce the font size of the header so that it can be accomodated in the BackupDestinationPanel.
        /// </summary>
        internal void reduceHeaderFontSize()
        {
            this.listView1.Font = new System.Drawing.Font("Microsoft Sans Serif", 7.4F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
        }
    }
}
